<?php
/*********************************************************************\
* This File is a part of BH-PANEL (Breizh-Heberg Panel v2.1)
* Copyright (C) 2008-2009 the BH Developpers : Vincent Giersch <mail@vincordi.fr>, Cyprien Laleau <fanning.fr@gmail.com> and Edwin Cabiten <marmottes44@hotmail.fr>
* See file AUTHORS to get more informations

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************/

if(isset($_SESSION['u_nic'])&&isset($_GET['id'])) {
	$title = "Protection du domaine";
	$tplinc = "panel-domaine-lock";
	$tpl->assign(array(
		'iconesleft' => 3,
		'prod' => '1',
		'prod_id' => intval($_GET['id'])
	));
	include('php/lib/panel_inc.php');
	$dom_current = intval($_GET['id']);
	$infos_dom = mysql_query("SELECT 
								comptes_domain.*,
								users.reg_contact_id,
								users.u_nic
								FROM comptes_domain
								LEFT JOIN users
								ON comptes_domain.u_nic = users.u_nic
								WHERE comptes_domain.id='".$dom_current."' AND comptes_domain.u_nic='".$_SESSION['u_nic']."'");
	if(mysql_num_rows($infos_dom) == 1) {
		$infos_dom = mysql_fetch_array($infos_dom);
		if($infos_dom['etat'] == "1") {
			$tpl->assign(array(
				"current_dom" => $infos_dom['domaine'],
				"action" => intval($_GET['action']),
				"zone_dns" => $infos_dom['zone_dns'],
				));
			if(intval($_GET['action'] == 0)&&intval($_GET['valid'] == 1)) {
					// Use class bh_doms_gest() :
					include ROOT.'php/lib/registrars/'.$registrar[$infos_dom['id_registrar']].'.inc.php';
					$_domgest = new bh_doms_gest();
					$update['dns1'] = $infos_dom['dns1'];
					$update['dns2'] = $infos_dom['dns2'];
					$update['dns3'] = $infos_dom['dns3'];
					$update['dns4'] = $infos_dom['dns4'];
					$update['reg_contact_id'] = $infos_dom['reg_contact_id'];
					$update['registry_status'] = 0;
					$tid = $_domgest->dom_update($infos_dom['domaine'],$update);
					query("UPDATE comptes_domain SET etat = '3', tid = '$tid', locked = '0' WHERE domaine = '".$infos_dom['domaine']."'");
					$_domgest->deconnect();
				header("Location: domaine.html?id=".intval($_GET['id']));
			}
			elseif(intval($_GET['action'] == 1)&&intval($_GET['valid'] == 1)) {
					// Use class bh_doms_gest() :
					include ROOT.'php/lib/registrars/'.$registrar[$infos_dom['id_registrar']].'.inc.php';
					$_domgest = new bh_doms_gest();
					$update['dns1'] = $infos_dom['dns1'];
					$update['dns2'] = $infos_dom['dns2'];
					$update['dns3'] = $infos_dom['dns3'];
					$update['dns4'] = $infos_dom['dns4'];
					$update['reg_contact_id'] = $infos_dom['reg_contact_id'];
					$update['registry_status'] = 64;
					$tid = $_domgest->dom_update($infos_dom['domaine'],$update);
					query("UPDATE comptes_domain SET etat = '3', tid = '$tid' , locked = '1' WHERE domaine = '".$infos_dom['domaine']."'");
					$_domgest->deconnect();
				header("Location: domaine.html?id=".intval($_GET['id']));
			}
			else {
				$parse = 1;
			}
		}
		else { header("Location:/panel/domaine.html?id=".intval($_GET['id'])); }
	}
}
else { header("Location:/site/connexion.html"); }
?>